﻿#include <stdio.h>
#include <malloc.h>
#include "state.h"

void main()
{ 
    int input,search,m;
    bool taller=false;
	int shorter=0;
    BSTree T,T1,T2,F;
    T=(BSTree)malloc(sizeof(BSTNode));
	F=(BSTree)malloc(sizeof(BSTNode));
    F=T=T1=T2=NULL;
	printf("\n\t******************************************************\n");
	printf("\t    \t    \t商品  \t查询  \t系统  \t    \t    ");
    printf("\n\t******************************************************\n");
	while(1)
	{
		printf("\n\t******************************************************\n");
		printf("\t1.创建\t2.查找\t3.插入\t4.删除\t5.原表\t6.添表\t7.退出");
        printf("\n\t******************************************************\n");
        printf("请输入您所需的操作功能:\t");
        scanf("%d",&input);getchar();   
		switch(input)
		{
		   case 1:
			   CreatBST(T); break;
		   case 2:
			   printf("请输入你要查找的商品:");
               scanf("%d",&search); getchar();
			   taller=false;
               if(SearchBST(T,search)) printf("<位于原表中>成功!\n");
			   else if(SearchBST(F,search)) printf("<位于添表中>\n查找成功!\n");
			   else 
			   {
					printf("已将未找到的商品添加到列表中。\n");
					printf("查找失败!\n");
					InsertAVL1(F,search,taller);
			   }
			   break;
		   case 3:
			   printf("请输入你要插入的商品:");
               scanf("%d",&search); getchar();
               InsertAVL(T,search,taller); m = 0;
			   PrintBST(T,m); break;
		   case 4:
			   printf("请输入你要删除的商品:");
			   scanf("%d",&search); getchar();
			   DeleteAVL(T,search,shorter);
			   m=0; PrintBST(T,m); break;
		   case 5:
			   m=0; PrintBST(T,m);
			   break;
		   case 6:
			   m=0; PrintBST(F,m);
			   break;
		   case 7:printf("\t\tbyebye!\n");break;
		   default:printf("输入错误，请重新选择。");break;
		}
		if(input == 7) break;
		printf("\t\t按任意键继续."); getchar();
	}


}




		
